<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>11函数柯里化</title>
</head>
<body>
  <div id="app"></div>
  <script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
  <script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
  <!-- 生产环境中不建议使用 -->
  <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/prop-types/15.7.2/prop-types.min.js"></script>

  <script type="text/babel">
    class Login extends React.Component {
      state = {
        username: '',
        password: ''
      }
  
      // 保存表单到state中
      onSaveData(dataType, event) {
        this.setState({
          [dataType]: event.target.value
        })
      }

      // 登录
      handleLogin = () => {
        const { username, password } = this.state
        console.log(`用户名是${username}, 密码是${password}`)
      }

      render() {
        return (
          <div>
            <p>用户名<input onChange={ event => this.onSaveData('username', event) } type="text" /></p>
            <p>密 码<input onChange={ event => this.onSaveData('password', event) } type="text" /></p>
            <button onClick={this.handleLogin}>登录</button>
          </div>
        )
      }
    }
    ReactDOM.render(<Login />, document.getElementById('app'))
  </script>
</body>
</html>